home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / bipl.zip / PROGS.ZIP / LOADMAP.ICN < prev    next >
Text File  |  1992-11-26  |  4KB  |  141 lines

  1. ############################################################################
  2. #
  3. #    File:     loadmap.icn
  4. #
  5. #    Subject:  Program to show load map of UNIX object file
  6. #
  7. #    Author:   Stephen B. Wampler
  8. #
  9. #    Date:     December 13, 1985
  10. #
  11. ###########################################################################
  12. #  
  13. #     This program produces a formatted listing of selected symbol classes
  14. #  from a compiled file.  The listing is by class, and gives the
  15. #  name, starting address, and length of the region associated with
  16. #  each symbol.
  17. #  
  18. #     The options are:
  19. #  
  20. #      -a Display the absolute symbols.
  21. #  
  22. #      -b Display the BSS segment symbols.
  23. #  
  24. #      -c Display the common segment symbols.
  25. #  
  26. #      -d Display the data segment symbols.
  27. #  
  28. #      -t Display the text segment symbols.
  29. #  
  30. #      -u Display the undefined symbols.
  31. #  
  32. #  If no options are specified, -t is assumed.
  33. #  
  34. #  If the address of a symbol cannot be determined, ???? is given in
  35. #  its place.
  36. #  
  37. ############################################################################
  38. #  
  39. #  Notes:
  40. #
  41. #     The size of the last region in a symbol class is suspect and is
  42. #  usually given as rem.
  43. #  
  44. #     Output is not particularly exciting on a stripped file.
  45. #  
  46. ############################################################################
  47. #
  48. #  Requires: UNIX
  49. #
  50. ############################################################################
  51.  
  52. record entry(name,address)
  53.  
  54. procedure main(args)
  55.    local maptype, arg, file, nm, ldmap, tname, line, text, data, bss
  56.    local SPACE, COLON, DIGITS, HEXDIGITS, usize, address, name, nmtype
  57.    initial {
  58.       if *args = 0 then stop("usage: loadmap [-t -d -b -u -a -c -l] file")
  59.       SPACE := '\t '
  60.       COLON := ':'
  61.       DIGITS := '0123456789'
  62.       HEXDIGITS := DIGITS ++ 'abcdef'
  63.       ldmap := table(6)
  64.       ldmap["u"] := []
  65.       ldmap["d"] := []
  66.       ldmap["a"] := []
  67.       ldmap["b"] := []
  68.       ldmap["t"] := []
  69.       ldmap["c"] := []
  70.       tname := table(6)
  71.       tname["u"] := "Undefined symbols"
  72.       tname["a"] := "Absolute locations"
  73.       tname["t"] := "Text segment symbols"
  74.       tname["d"] := "Data segment symbols"
  75.       tname["b"] := "BSS segment symbols"
  76.       tname["c"] := "Common symbols"
  77.       nmtype := "nm -gno "
  78.       }
  79.    maptype := ""
  80.    every arg := !args do
  81.       if arg[1] ~== "-" then file := arg
  82.       else if arg == "-l" then nmtype := "nm -no "
  83.       else if arg[1] == "-" then maptype ||:= (!"ltdbuac" == arg[2:0]) |
  84.          stop("usage:  loadmap [-t -d -b -u -a -c -l] file")
  85.    maptype := if *maptype = 0 then "t" else string(cset(maptype))
  86.    write("\n",file,"\n")
  87.    usize := open("size " || file,"rp") | stop("loadmap: cannot execute size")
  88.    !usize ? {
  89.       writes("Text space: ",right(text := tab(many(DIGITS)),6),"   ")
  90.       move(1)
  91.       writes("Initialized Data: ",right(data := tab(many(DIGITS)),6),"   ")
  92.       move(1)
  93.       write("Uninitialized Data: ",right(bss := tab(many(DIGITS)),6))
  94.       }
  95.    close(usize)
  96.    nm := open(nmtype || file,"rp") | stop("loadmap: cannot execute nm")
  97.    every line := !nm do
  98.       line ? {
  99.          tab(upto(COLON)) & move(1)
  100.          address := integer("16r" || tab(many(HEXDIGITS))) | "????"
  101.          tab(many(SPACE))
  102.          type := map(move(1))
  103.          tab(many(SPACE))
  104.          name := tab(0)
  105.          if find(type,maptype) then put(ldmap[type],entry(name,address))
  106.          }
  107.    every type := !maptype do {
  108.       if *ldmap[type] > 0 then {
  109.          write("\n\n\n")
  110.          write(tname[type],":")
  111.          write()
  112.          show(ldmap[type],(type == "t" & text) |
  113.             (type == "d" & data) | (type == "b" & bss) | &null,
  114.             ldmap[type][1].address)
  115.          }
  116.       }
  117. end
  118.  
  119. procedure show(l,ssize,base)
  120.    local i1, i2, nrows
  121.    static ncols
  122.    initial ncols := 3
  123.    write(repl(repl(" ",3) || left("name",9) || right("addr",7) ||
  124.       right("size",6),ncols))
  125.    write()
  126.    nrows := (*l + (ncols - 1)) / ncols
  127.    every i1 := 1 to nrows do {
  128.       every i2 := i1 to *l by nrows do
  129.          writes(repl(" ",3),left(l[i2].name,9),right(l[i2].address,7),
  130.             right(area(l[i2 + 1].address,l[i2].address) |
  131.             if /ssize then "rem" else base + ssize - l[i2].address,6))
  132.          write()
  133.          }
  134.    return
  135. end
  136.  
  137. procedure area(high,low)
  138.    if integer(low) & integer(high) then return high - low
  139.    else return "????"
  140. end
  141.